/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data.logic;

import data.Building;
import data.BuildingType;
import java.awt.Color;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToggleButton;

/**
 *
 * @author Jonas
 */
public class BuildingSquareType extends SquareType {

    private Building building;
    private JButton btnLevelUp = null;
    private JButton btnDestroy = null;
    private Vector<JToggleButton> buildButtons = null;
    private JButton btnBuildWall = null;

    public BuildingSquareType(Building building) {

        setBuilding(building);
        setBuildingPossible(false);
        setColor(new Color(95, 195, 89));
        setImageUrl(building.getImageUrl());


        // Load LevelUp Button
        btnLevelUp = new JButton(new ImageIcon("src/img/levelUp.gif"));
        btnLevelUp.setContentAreaFilled(false);

        // 0 means it's a Town Center Type
        // 1 => ProductionBuilding
        // 2 => Military Building
        if (building.getType() == 0) {
            // Load buildingButtons
            buildButtons = new Vector<JToggleButton>();
            Vector<BuildingType> buildingTypes = BuildingSquareTypeFactory.getInstance().getTypes();
            for (BuildingType buildingType : buildingTypes) {
                ImageIcon image = new ImageIcon(buildingType.getBtnImageUrl());
                JToggleButton buildButton = new JToggleButton(new ImageIcon(buildingType.getBtnImageUrl()));
                buildButton.setActionCommand(buildingType.getName());
                buildButtons.add(buildButton);
            }

        } else if (building.getType() == 1) {
            // Load Destruct Button
            btnDestroy = new JButton(new ImageIcon("src/img/destroy.gif"));
            btnDestroy.setContentAreaFilled(false);
        } else if (building.getType() == 2) {
            // Load Destruct Button
            btnDestroy = new JButton(new ImageIcon("src/img/destroy.gif"));
            btnDestroy.setContentAreaFilled(false);
        // Load BuildWall Button
        }

    }

    public Building getBuilding() {
        return building;
    }

    public void setBuilding(Building building) {
        this.building = building;
    }

    public JButton getBtnLevelUp() {
        return btnLevelUp;
    }

    public JButton getBtnDestroy() {
        return btnDestroy;
    }

    public Vector<JToggleButton> getBuildButtons(int villageLevel) {
        buildButtons.removeAllElements();

        Vector<BuildingType> buildingTypes = BuildingSquareTypeFactory.getInstance().getTypes();
        for (BuildingType buildingType : buildingTypes) {
            if (buildingType.getMinLevel() <= villageLevel) {
                ImageIcon image = new ImageIcon(buildingType.getBtnImageUrl());
                JToggleButton buildButton = new JToggleButton(new ImageIcon(buildingType.getBtnImageUrl()));
                buildButton.setActionCommand(buildingType.getName());
                buildButtons.add(buildButton);
            }
        }

        return buildButtons;
    }

    public JButton getBtnBuildWall() {
        return btnBuildWall;
    }
}
